package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.BtyTz;
import cn.stylefeng.guns.sys.modular.system.mapper.BtyTzMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyTzParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyTzResult;
import  cn.stylefeng.guns.sys.modular.system.service.BtyTzService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liuy
 * @since 2022-03-04
 */
@Service
public class BtyTzServiceImpl extends ServiceImpl<BtyTzMapper, BtyTz> implements BtyTzService {

    @Override
    public void add(BtyTzParam param){
        BtyTz entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BtyTzParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BtyTzParam param){
        BtyTz oldEntity = getOldEntity(param);
        BtyTz newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BtyTzResult findBySpec(BtyTzParam param){
        return null;
    }

    @Override
    public List<BtyTzResult> findListBySpec(BtyTzParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BtyTzParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public boolean insertTz(List<BtyTz> list) {
        return baseMapper.insertTz(list);
    }

    @Override
    public List<BtyTzResult> tzList() {
        return baseMapper.tzList();
    }

    @Override
    public List<BtyTzResult> customList(BtyTzParam param) {
        return baseMapper.customList(param);
    }

    private Serializable getKey(BtyTzParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BtyTz getOldEntity(BtyTzParam param) {
        return this.getById(getKey(param));
    }

    private BtyTz getEntity(BtyTzParam param) {
        BtyTz entity = new BtyTz();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
